package com.example.goodpet.my;


import android.annotation.SuppressLint;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.signature.ObjectKey;
import com.example.goodpet.R;
import com.example.goodpet.my.activity.MyFensiActivity;
import com.example.goodpet.my.activity.MyFollowActivity;
import com.example.goodpet.my.activity.MyInformationActivity;
import com.example.goodpet.my.activity.MyLikesActivity;
import com.example.goodpet.my.activity.MyPetCollectActivity;
import com.example.goodpet.my.activity.MyReleaseActivity;
import com.example.goodpet.my.activity.MyHistoryActivity;
import com.example.goodpet.my.activity.SettingActivity;
import com.example.goodpet.base.BaseFragment;
import com.example.goodpet.utils.Constants;
import com.example.goodpet.utils.MyApplication;
import com.example.goodpet.utils.UIUtils;

public class MyFragment extends BaseFragment implements View.OnClickListener {
    private final String TAG="MyFragment";
    private TextView titleText;
    private ImageView cmTitleLeft;
    private TextView cmTitleRight;

    private ImageView myPortrait;
    private TextView myNickname;

    private LinearLayout myTiezi;
    private LinearLayout myCollection;
    private LinearLayout myHistory;
    private LinearLayout MyFollow;
    private LinearLayout MyFensi;
    private LinearLayout MySettings;
    private LinearLayout MyLikes;
    private RelativeLayout myInformation;


    public long newChangeDate=0;
    /**
     * 初始化主页面Fragment的UI
     */
    @Override
    public View initView() {
        View view = UIUtils.getView(R.layout.fragment_my);
        titleText=view.findViewById(R.id.cmTitleText);
        myTiezi=view.findViewById(R.id.myTiezi);
        myHistory=view.findViewById(R.id.myHistory);
        MyFollow=view.findViewById(R.id.myFollow);
        MyFensi=view.findViewById(R.id.myFensi);
        MyLikes=view.findViewById(R.id.myLike);
        MySettings=view.findViewById(R.id.mySettings);
        myCollection=view.findViewById(R.id.myCollection);
        myInformation=view.findViewById(R.id.myInformation);
        myPortrait=view.findViewById(R.id.myPortrait);
        myNickname=view.findViewById(R.id.myNickname);

        cmTitleLeft=view.findViewById(R.id.cmTitleLeft);
        cmTitleRight=view.findViewById(R.id.cmTitleRight);
        //设置监听
        myTiezi.setOnClickListener(this);
        myHistory.setOnClickListener(this);
        MyFollow.setOnClickListener(this);
        MyFensi.setOnClickListener(this);
        MySettings.setOnClickListener(this);
        myCollection.setOnClickListener(this);
        MyLikes.setOnClickListener(this);

        myInformation.setOnClickListener(this);
        return view;
    }

    @Override
    public void initTitle() {
        titleText.setText("我的");
        cmTitleLeft.setVisibility(View.INVISIBLE);
        cmTitleRight.setVisibility(View.INVISIBLE);
    }

    /**
     * 初始化主页面Fragment的数据
     */
    @Override
    public void initData() {
        super.initData();
    }

    @Override
    public void onResume() {
        super.onResume();
        myNickname.setText(MyApplication.user.getNickname());

        Glide.with(this)
                .load(Constants.BASE_URL_IMAGE+MyApplication.user.getPortrait()).signature(new ObjectKey(newChangeDate)).into(myPortrait);
    }

    @SuppressLint("NonConstantResourceId")
    @Override
    public void onClick(View v) {
        Intent intent=null;
        switch(v.getId()){
            case R.id.myTiezi:
                //newChangeDate=System.currentTimeMillis();
                intent = new Intent(getActivity(), MyReleaseActivity.class);
                startActivity(intent);
                break;
            case R.id.myHistory:
                intent = new Intent(getActivity(), MyHistoryActivity.class);
                startActivity(intent);break;
            case R.id.myFollow:
                intent = new Intent(getActivity(), MyFollowActivity.class);
                intent.putExtra("userId",MyApplication.user.getId());
                startActivity(intent);break;
            case R.id.myFensi:
                intent = new Intent(getActivity(), MyFensiActivity.class);
                intent.putExtra("userId",MyApplication.user.getId());
                startActivity(intent);break;
            case R.id.mySettings:
                intent = new Intent(getActivity(), SettingActivity.class);
                startActivity(intent);
                break;
            case R.id.myCollection:
                intent = new Intent(getActivity(), MyPetCollectActivity.class);
                startActivity(intent);break;
            case R.id.myInformation:
                newChangeDate=System.currentTimeMillis();
                intent = new Intent(getActivity(), MyInformationActivity.class);
                startActivity(intent);break;
            case R.id.myLike:
                intent = new Intent(getActivity(), MyLikesActivity.class);
                intent.putExtra("userId",MyApplication.user.getId());
                startActivity(intent);break;

        }
    }
}
